﻿using System;

using System.ServiceModel;


namespace KATS_Server
{
    /// <summary>
    /// The server's publicly accessable functions
    /// </summary>
    [ServiceContract(Namespace = "http://www.animeequation.com/", SessionMode = SessionMode.Required)]
    interface IServer
    {
        /// <summary>
        /// Close all file handles on the current file
        /// </summary>
        [OperationContract(IsInitiating = false)]
        void CloseFile();

        /// <summary>
        /// Close the file reader
        /// </summary>
        [OperationContract(IsInitiating = false)]
        void CloseReader();

        /// <summary>
        /// Close the file writer
        /// </summary>
        [OperationContract(IsInitiating = false)]
        void CloseWriter();

        /// <summary>
        /// Copy current object to target
        /// </summary>
        /// <param name="target">Target location</param>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool Copy(string target);

        /// <summary>
        /// Create a directory
        /// </summary>
        /// <param name="location">Where?</param>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool CreateDirectory(string location);

        /// <summary>
        /// Delete the current object
        /// </summary>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool Delete();

        /// <summary>
        /// Does this object exist?
        /// </summary>
        /// <returns>Exists?</returns>
        [OperationContract(IsInitiating = false)]
        bool Exists();

        /// <summary>
        /// Is there an object at this location
        /// </summary>
        /// <param name="Loc">The location of the file</param>
        /// <returns>True if exists</returns>
        [OperationContract(IsInitiating = false)]
        bool Exist(string Loc);

        /// <summary>
        /// The size of the file
        /// </summary>
        /// <param name="location">File location</param>
        /// <returns>File Size</returns>
        [OperationContract(IsInitiating = false)]
        long FileLength(string location);

        /// <summary>
        /// The size of the Directory
        /// </summary>
        /// <param name="location">The location</param>
        /// <param name="recursive">Include subdirectories?</param>
        /// <returns>Folder size</returns>
        [OperationContract(IsInitiating = false)]
        long DirectoryLength(string location, bool recursive);

        /// <summary>
        /// Get the files in the active directory
        /// </summary>
        /// <returns>File array</returns>
        [OperationContract(IsInitiating = false)]
        string[] GetDirectoryFiles();

        /// <summary>
        /// Get the files in the directory
        /// </summary>
        /// <param name="location">The location</param>
        /// <returns>The files</returns>
        [OperationContract(IsInitiating = false)]
        string[] GetDirectoryFilesS(string location);

        /// <summary>
        /// Get the next file chunk from the server
        /// </summary>
        /// <returns>The file bytes</returns>
        [OperationContract(IsInitiating = false)]
        byte[] GetFileChunk();

        /// <summary>
        /// Get the logical HDDs on the server
        /// </summary>
        /// <returns>The HDDs</returns>
        [OperationContract(IsInitiating = false)]
        string[] GetHDDs();

        /// <summary>
        /// Get the subdirectories in the current directory
        /// </summary>
        /// <returns>The subdirectories</returns>
        [OperationContract(IsInitiating = false)]
        string[] GetSubDirectories();

        /// <summary>
        /// Get the sub directories in the provided directory
        /// </summary>
        /// <param name="Directory">The location</param>
        /// <returns>The subdirectories</returns>
        [OperationContract(IsInitiating = false)]
        string[] GetSubDirectoriesS(string Directory);

        /// <summary>
        /// Move the current file to the target area
        /// </summary>
        /// <param name="target">Where to move the file/folder to?</param>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool Move(string target);

        /// <summary>
        /// Open the file reader
        /// </summary>
        [OperationContract(IsInitiating = false)]
        void OpenReader();

        /// <summary>
        /// Open the file writer
        /// </summary>
        [OperationContract(IsInitiating = false)]
        void OpenWriter();

        /// <summary>
        /// Print a message out on the server
        /// </summary>
        /// <param name="msg">The message</param>
        [OperationContract(IsInitiating = false)]
        void PrintMessage(string msg);

        /// <summary>
        /// Rename a file/folder on the server
        /// </summary>
        /// <param name="target">The object to rename</param>
        /// <param name="newTarget">The new name</param>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool Rename(string target, string newTarget);

        /// <summary>
        /// Reset the file writer to the start of the file
        /// </summary>
        [OperationContract(IsInitiating = false)]
        void ResetWriter();

        /// <summary>
        /// Send a file chunk to the server
        /// </summary>
        /// <param name="fileBytes">The file bytes</param>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool SendFileChunk(byte[] fileBytes);

        /// <summary>
        /// Set the active folder location
        /// </summary>
        /// <param name="location">The target location</param>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool SetLocation(string location);

        /// <summary>
        /// Undo the previous read operation
        /// </summary>
        /// <returns>Successful?</returns>
        [OperationContract(IsInitiating = false)]
        bool UndoRead();

        /// <summary>
        /// Connect to the server using the following username and password
        /// </summary>
        /// <param name="username">The username</param>
        /// <param name="password">The password</param>
        /// <returns>Is connection successful?</returns>
        [OperationContract(IsInitiating = true)]
        bool Authenticate(string username, string password);

        /// <summary>
        /// Disconnect from the server
        /// </summary>
        [OperationContract(IsInitiating = false, IsTerminating = true)]
        void Disconnect();

        /// <summary>
        /// Wait x milliseconds
        /// </summary>
        /// <param name="time">Wait x milliseconds</param>
        /// <returns>True</returns>
        [OperationContract(IsInitiating = false)]
        bool Wait(int time);


        /// <summary>
        /// Get the files and file sizes for a directory
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        [OperationContract(IsInitiating = false)]
        string[] GetDirectoryFilesAndSizes(string location);


    }
}
